/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.pucp.TrabajoGrupal.Classes;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Vector;

/**
 *
 * @author andre
 */
public class ProjectDao {
        private Connection con = null;
    private Statement st = null;
    private ResultSet rs = null;
    
    public ProjectDao(){
       
    }

    
    private void conectar(){
         try
        {
            String url = "jdbc:mysql://localhost:3306/dbproyectos";
            String usr = "root";
            String password = "";
            //Class.forName("com.mysql.jdbc.Driver");
            //DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
            con = DriverManager.getConnection (url,usr, password);            
        } catch (SQLException ex) {
            System.out.println( ex );
        }
    }
    private void cerrar(){
        try{
            st.close();
            con.close();
        }
        catch(Exception e){
        
        }
    }
    
    public ArrayList<Project> getProjects(){
        ArrayList<Project> ans = new ArrayList<Project>();
        conectar();
        try{
            String query = "SELECT proyectoid , proyecto , inicio , fin FROM proyecto";
            st = con.createStatement();
            rs = st.executeQuery(query);
            while (rs.next()){
                Project node = new Project();
                node.setId( Integer.parseInt(rs.getString("proyectoid")));
                node.setName( rs.getString("proyecto"));
                node.setStartDate( rs.getString("inicio") );
                node.setFinishDate( rs.getString("fin" ) );
                ans.add(node);
            }
            
        }
        catch(Exception e){
            System.out.println( e );
        }
        cerrar();
        return ans;
    } 
}
